﻿
@functions{

    IEnumerable<dynamic> _MenuDt;
    IEnumerable<dynamic> _CanAdminTable;
    string ShowLeftMenu(IEnumerable<dynamic> menuDt, IEnumerable<dynamic> canAdminTable)
    {
        _MenuDt = menuDt;
        _CanAdminTable = canAdminTable;
        string rv = "";
        IEnumerable<dynamic> levelDataList = menuDt.Where(item => item.Level == 1);
        foreach (var row in levelDataList)
        {
            rv += "<div id=\"menu" + row.Id + "\">\r\n" + ChildMenu(menuDt, row.Id) + "\r\n</div>";
        }
        return rv;
    }

    string ChildMenu(IEnumerable<dynamic> menuDt, int parentId)
    {
        string rv = "<ul>";
        IEnumerable<dynamic> dataList = menuDt.Where(item => item.ParentId == parentId);
        foreach (var item in dataList)
        {
            string isExpand = item.IsExpand.ToString();
            int id =item.Id;
            string area = item.Area.ToString();
            int level = item.Level;
            string target = item.Target;
            if (!string.IsNullOrEmpty(target))
            {
                target = " target=\""+ target+ "\" ";
            }
            string pluginName= item.PluginName;
            byte isFinal = item.IsFinal;
            string url = item.ZdyUrl;
            if (isFinal == 1 && string.IsNullOrEmpty(url))
            {
                if(pluginName!="")
                {
                    url = Url.RouteUrl("Plugin",new {action= item.Action.ToString(), controller=item.Controller.ToString(),pluginName= pluginName});
                }
                else
                {
                    url = Url.Action(item.Action.ToString(), item.Controller.ToString(),new{area = area });
                }
                if(string.IsNullOrEmpty(url))
                {
                    url = "";
                }
            }

            string className = "";
            string nodeType = item.SysNode;
            string arrow = "";
            if (isFinal == 0)
            {
                arrow = "<span class=\"fa fa-fw fa-angle-right arrow-icon\"></span>";
            }
            if (isExpand == "0")
            {
                className = "shut";
            }
            if (!string.IsNullOrEmpty(url))
            {
                url = "href=\"" + url + "\"";
            }
            string icon="";
            if (isFinal ==0)
            {
                icon = item.Icon;
                if (icon=="")
                {
                    icon = " fa-cog";
                }
                icon = "<i class=\"sign-icon fa-fw fa " + icon +"\"></i>";
            }

            rv += "\r\n<li>\r\n<a data-isFinal=\""+isFinal+"\" data-pluginName=\"" + pluginName+ "\"" + target+" data-menuid =\"" + item.Id + "\" " + url + " class=\"" + className + "\">" + icon+"<span>"+item.Name+"</span>"+ arrow + "</a>";
            if (isFinal == 0)
            {
                if (nodeType == "infoData")
                {
                    rv += InfoTableMenu();
                }
                else if (nodeType == "UserNode")
                {
                    //rv += MenuTypeMenu();
                }
                else
                {

                }
                string childNode = ChildMenu(menuDt,id);
                if (childNode != "<ul></ul>")
                {
                    rv += childNode;
                }
            }
            rv += "\r\n</li>";
        }
        rv += "</ul>";
        return rv;
    }


    string InfoTableMenu()
    {
        if (_CanAdminTable == null)
        {
            return "";
        }
        string rv = "\r\n<ul>";
        foreach (var item in _CanAdminTable)
        {
            string className = "";
            string url = Url.Action("Index", "InfoData", new { table = item.Name,area="Member"});
            rv += "\r\n<li>\r\n<a data-menuId=\"info_" + item.Id + "\" href =\"" + url + "\" class=\"" + className + "\"><span>" + item.Remark + "</span></a>";
            rv += "\r\n</li>";
        }
        rv += "\r\n</ul>";
        return rv;
    }

    //string MenuTypeMenu()
    //{
    //    if (_CanAdminMemberType == null)
    //    {
    //        return "";
    //    }
    //    string rv = "\r\n<ul>";
    //    IDataReader dr = CanAdminMemberType;
    //    while (item.Read())
    //    {
    //        string className = "";
    //        string url = Url.ActionUrl("Index", "Member", new { member_type_id = dr["id"].ToString() });
    //        rv += "\r\n<li>\r\n<a menuid=\"membertype_" + dr["id"].ToString() + "\" href =\"" + url + "\" class=\"" + className + "\"><i class=\"leftline\"></i>" + dr["name"].ToString() + "</a>";
    //        rv += "\r\n</li>";
    //    }
    //    item.Close();
    //    rv += "\r\n</ul>";
    //    return rv;
    //}

}

<div class="leftmenu-classname icon-menu-switch"><span class="fa fa-bars"></span> <span id="className"></span></div>
<div class="leftmenu" id="leftmenu">
    @{
        //string adminPath = "/" + this.ViewContext.RouteData.Values["adminPath"].ToString();//当前站点path
        IEnumerable<dynamic> menuList = (IEnumerable<dynamic>)ViewData["MenuList"];
        IEnumerable<dynamic> canAdminTableList = (IEnumerable<dynamic>)ViewData["CanAdminTableList"];
        <Text>@Html.Raw(ShowLeftMenu(menuList, canAdminTableList))</Text>
    }
</div>





